package com.start.admin.controller;

import com.start.admin.entity.StartSysRoleDataRule;
import com.start.admin.service.StartSysRoleDataRuleService;
import com.start.common.api.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/start/sysRoleDataRule")
public class StartSysRoleDataRuleController {
    @Autowired
    private StartSysRoleDataRuleService startSysRoleDataRuleService;

    @PostMapping("/save/{roleId}/{menuId}")
    public Result<?> save(@PathVariable("roleId") String roleId,
                          @PathVariable("menuId") String menuId,
                          @RequestBody List<String> dataRuleIds) {
        startSysRoleDataRuleService.saveDataRules(roleId, menuId, dataRuleIds);
        return Result.ok();
    }

    @GetMapping("/getList/{roleId}/{menuId}")
    public Result<?> getList(@PathVariable("roleId") String roleId,
                             @PathVariable("menuId") String menuId) {
        List<StartSysRoleDataRule> startSysRoleDataRules = startSysRoleDataRuleService.getListByRoleIdAndMenuId(roleId, menuId);
        return Result.ok(startSysRoleDataRules);
    }
}
